panda = {
	post: function(req, success, failure) {
		if ($.type(req) === "string") {
			req = { action: req }
		}

		$.post("api", { request : $.toJSON(req) }, function(result){
			if (result.success) {
				success && success(result.data);
			} else if (failure) {
				failure(result.error);
			} else {
				alert("Operation Failed!");
			}
		}, "json");
	},
	open: function(request) {
		request = $.toJSON(request);
		window.open("api?request=" + encodeURIComponent(request));
	},
	formatSize: function(bytes){
		var units = [" KB", " MB", " GB", " TB", " PB", " EB"];

		var i = -1;
		do {
			bytes = bytes / 1024;
			i++;  
		} while (bytes > 99);

		return Math.max(bytes, 0.1).toFixed(1) + units[i];		  
	},
	shorten: function(name, length){
		var length = length || 33;		
		if (name.length > length){
			var prefix = (length - 1) / 2 + 3;
			var post = Math.max(0, length - prefix);
			name = name.slice(0, prefix) + "..." + name.slice(-post);	
		}
		return name;
	},
	safari: $.browser.webkit && navigator.userAgent.toLowerCase().indexOf("chrome") < 0
}
